<template>
	<div class="count">
		<h2>当前求和为:{{$store.state.sum}}</h2>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">加</button>
		<button @click="decrement">减</button>
		<button @click="incrementIfOdd">当前和为奇数再加</button>
		<button @click="incrementWait">等一等再加</button>
		<button @click="incrementAjax">联系一下服务器，看看加几</button>
	</div>
</template>

<script>
	export default {
		name:'Count',
		data() {
			return {
				n:1,
			}
		},
		methods: {
			//加法
			increment(){
				this.$store.commit('JIA',this.n)
			},
			//减法
			decrement(){
				this.$store.commit('JIAN',this.n)
			},
			//和为奇数再加
			incrementIfOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			//等一等再加
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			},
			//联系服务器加
			incrementAjax(){
				this.$store.dispatch('jiaAjax')
			}
		},	
		mounted(){
			console.log(this)
		}
	}
</script>

<style>
	.count{
		background-color: skyblue;
		padding: 20px;
	}
	select,button{
		height: 30px;
		margin-right: 10px;
	}
</style>